﻿using Microsoft.AspNetCore.SignalR.Client;
using System;
using System.Threading;
using System.Threading.Tasks;

namespace console
{
    class Program
    {
        static void Main(string[] args)
        {
            EventWaitHandle _mainProcessEventWait = new EventWaitHandle(false, EventResetMode.ManualReset);//主线程等待
            bool _run = true;
            SignalrClient.Instance.StartAsync().Wait();//开始连接
            SignalrClient.Instance.On<string>("ReceiveMessage", message =>
            {
                Console.Out.WriteLineAsync(message);//接受消息
            });
            Task.Factory.StartNew(() =>
            {
                while (_run)
                {
                    var msg = Console.ReadLine();
                    if (msg == "exit" || msg == "exit;")
                    {
                        _run = false;
                        _mainProcessEventWait.Set();
                    }
                    else
                    {
                        SignalrClient.Instance.SendAsync("SendMessageAll", msg).Wait();
                    }
                }
            });
;            _mainProcessEventWait.WaitOne();

        }
    }
}
